package top.pmwly.oauth2.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;

/**
 * @author Herther
 * @version 1.0.0
 * @ClassName AuthorizationServerConfig.java
 * @Description 授权服务器配置类
 * @createTime 2021年08月21日 17:33:00
 */
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {


    @Autowired
    PasswordEncoder passwordEncoder;

    /**
     * 授权服务器的配置
     * @param clients
     * @throws Exception
     */
    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory()
                //授权服务器中注册时出来的，这里方便演示就放到内存中 用户名
                .withClient("admin")
                //密码
                .secret(passwordEncoder.encode("666"))
                //令牌失效时间 3600秒
                .accessTokenValiditySeconds(3600)
                //重定向到百度，用于授权成功后跳转
                .redirectUris("https://www.baidu.com")
                //配置申请的权限范围
                .scopes("all")
                //配置授权码模式
                .authorizedGrantTypes("authorization_code");
    }


}
